package com.guo.hui.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guo.hui.dao.blog.TpCommentMapper;
import com.guo.hui.model.blog.TpArticle;
import com.guo.hui.model.blog.TpComment;
import com.guo.hui.page.PageParam;
import com.guo.hui.service.CommentService;

@Service("commentService")
public class CommentServiceImpl implements CommentService {

	@Autowired
	private TpCommentMapper commentDao;

	@Override
	public void saveComment(TpComment tp) {
		SimpleDateFormat farmat = new SimpleDateFormat("yyyy-MM-mm");
		String time = farmat.format(new Date());
		tp.setTime(time);
		commentDao.insert(tp);

	}

	@Override
	public void updateComment(TpComment tp) {
		commentDao.update(tp);

	}

	@Override
	public List<TpComment> selectByMap(Map<String, Object> map) {
		List<TpComment> list = commentDao.selectByMap(map);
		return list;
	}

	@Override
	public PageInfo<TpComment> selectByMapPage(PageParam pageParm) {
		PageHelper.startPage(pageParm.getPage(), pageParm.getPageSize());
		List<TpComment> list = commentDao.selectByMap(pageParm.getSearchContent());
		return new PageInfo<TpComment>(list);
	}

}
